package br.com.projeto.dao.hql;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import br.com.projeto.sakila.bean.FilmText;

public class FilmTextDao {
	
	private SessionFactory sessionFactory;
	private Session session;

	public FilmTextDao(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public long buscarFilmText() {
		long tempoInicial = System.currentTimeMillis();
		List<FilmText> listaFilmText = new ArrayList<>();
		try {
			session = sessionFactory.openSession();		
			
			listaFilmText = session.createQuery("from FilmText").list();
			
			session.close();
		} catch (Exception e) {
			System.err.println("Erro : " + e);
		}
		long tempoFinal = System.currentTimeMillis(); 
		long tempo = tempoFinal - tempoInicial;
		return tempo;
	}
	
	public void listarFilmText(List<FilmText> lista){
		System.out.println("---------------------------");
		for (FilmText filmText : lista) {
			System.out.println("ID : " + filmText.getId());
			System.out.println("TITLE : " + filmText.getTitle());
			System.out.println("DESCRIPTION : " + filmText.getDescription());
			System.out.println("---------------------------");
		}
	}
	
}
